package com.jmxcfc.blfsc.common.common.response;

import com.jmxcfc.blfsc.common.common.enums.BaseErrorEnum;
import com.jmxcfc.blfsc.common.common.enums.ProcessStateEnum;
import lombok.Data;
import lombok.ToString;

/**
 * 公共响应报文
 * @param <T>
 */
@Data
@ToString
public class BaseResponse<T> {

    /**
     * 响应头
     */
    private HeaderResponse header = new HeaderResponse();

    /**
     * 响应体
     */
    T body;

    public BaseResponse() {
    }


    public BaseResponse(T body) {
        this.header = new HeaderResponse(BaseErrorEnum.OK);
        this.body = body;
    }

    public BaseResponse(BaseErrorEnum baseErrorEnum) {
        this.header = new HeaderResponse(baseErrorEnum);
        this.body = null;
    }

    public BaseResponse(BaseErrorEnum baseErrorEnum,T body) {
        this.header = new HeaderResponse(baseErrorEnum);
        this.body = body;
    }

    public BaseResponse(String resCode, String resMessage,T body) {
        this.header = new HeaderResponse(resCode,resMessage);
        this.body = body;
    }

    public BaseResponse(ProcessStateEnum processStateEnum,BaseErrorEnum baseErrorEnum, String resMessage) {
        this.header = new HeaderResponse(processStateEnum, baseErrorEnum, resMessage);
        this.body = null;
    }



    public BaseResponse(String resCode, String resMessage) {
        this.header = new HeaderResponse(resCode,resMessage);
        this.body = null;
    }

    public static <T> BaseResponse<T> success(T body){
        return new BaseResponse<>(body);
    }

    public static <T> BaseResponse<T> success(String resCode, String resMessage,T body){
        return new BaseResponse<>(resCode,resMessage,body);
    }

    public static <T> BaseResponse<T> fail(BaseErrorEnum baseErrorEnum){
        return new BaseResponse<>(baseErrorEnum);
    }


    public static <T> BaseResponse<T> fail(ProcessStateEnum processStateEnum, BaseErrorEnum baseErrorEnum, Exception e) {
        return new BaseResponse<>(processStateEnum, baseErrorEnum, e.getMessage());
    }


    public static <T> BaseResponse<T> fail(ProcessStateEnum processStateEnum, BaseErrorEnum baseErrorEnum, String errMsg) {
        return new BaseResponse<>(processStateEnum, baseErrorEnum, errMsg);
    }
}
